package logic

import (
	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"
	"baidu/models/mysql"
	"context"
	"fmt"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论添加
func (l *CommentAddLogic) CommentAdd(in *baidurpc.CommentAddRequest) (*baidurpc.CommentAddResponse, error) {
	// todo: add your logic here and delete this line

	if strings.Contains(in.Context, "草") || strings.Contains(in.Context, "妈") {
		return nil, fmt.Errorf("评论包含敏感词，不能添加")
	}

	comment := mysql.Comment{
		Context: in.Context,
		Publish: in.Publish,
	}

	mysql.DB.Debug().Create(&comment)

	return &baidurpc.CommentAddResponse{
		Id: int64(comment.ID),
	}, nil
}
